<template>
  <div class="MyWallet">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <div class="MyWallet_cont">
        <p>可提现金额</p>
        <p>{{ $common.formatMoney(userAmount) }}</p>
      </div>
      <!-- 图标 -->
      <van-row class="MyWallet_icon" gutter="10">
        <van-col span="12">
          <div class="MyWallet_icon_item">
            <h2><img src="@/assets/MyWallet_icon1.png" /> 总金额</h2>
            <h2>{{ $common.formatMoney(sumAmount) }}</h2>
          </div>
        </van-col>
        <van-col span="12">
          <div class="MyWallet_icon_item">
            <h2><img src="@/assets/MyWallet_icon.png" /> 在途金额</h2>
            <h2>{{ $common.formatMoney(onAmount) }}</h2>
          </div>
        </van-col>
      </van-row>
      <!-- 提现列表 -->
      <h3 class="MyWallet_title">我的钱包</h3>
      <ul v-if="withdrawList.length > 0">
        <li class="MyWallet_item" v-for="(item, index) in withdrawList" :key="index">
          <van-row>
            <van-col span="6">
              <img
                src="@/assets/yongjin.png"
              />
            </van-col>
            <van-col span="18">
              <div class="MyWallet_item_name">
                <h3>+{{ $common.formatMoney(item.amount) }}</h3>
                <p>{{ $common.getExactTime(item.createTime) }}</p>
              </div>
            </van-col>
          </van-row>
        </li>
      </ul>
      <van-empty v-else />
    </van-list>
    <div class="Withdrawal_button">
      <van-button
        block
        color="#D2A166"
        type="primary"
        @click="$router.push(`/withdrawal/${userAmount}`)"
        >去提现</van-button
      >
    </div>
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
import { Col, Row, List, Button, Empty } from "vant";
Vue.use(Empty);
Vue.use(List);
Vue.use(Col);
Vue.use(Row);
Vue.use(Button);
@Component({})
export default class MyWallet extends Vue {
  private withdrawList = [];
  private loading: boolean = false;
  private finished: boolean = false;
  private onAmount = 0;
  private sumAmount = 0;
  private userAmount = 0;
  private form = {
    page: 1,
    size: 20,
  };

  private onLoad() {
    this.$common.getAuthToken(this.getData);
  }

  private getData() {
    this.$post(`userWithdrawList`, this.form).then((res: any) => {
      if (res.code == 0) {
        this.loading = false;
        this.onAmount = res.data.onAmount;
        this.sumAmount = res.data.sumAmount;
        this.userAmount = res.data.userAmount;
        this.withdrawList = this.withdrawList.concat(res.data.list);
        this.form.page += 1;
        if (res.data.list.length < 20) {
          this.finished = true;
        }
      }
    });
  }
}
</script>

<style lang="scss" scope>
.MyWallet {
  width: 100%;
  padding: 30px 15px;
  box-sizing: border-box;
  margin-bottom: 100px;
  .MyWallet_cont {
    width: 100%;
    height: 200px;
    border-radius: 15px;
    background-image: url("~@/assets/MyWallet.png");
    background-position: center;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    padding: 50px;
    box-sizing: border-box;
    p {
      font-size: 36px;
      font-weight: 300;
      color: #ffffff;
      line-height: 1.3;
    }
  }
  .MyWallet_icon {
    padding: 30px 0;
    .MyWallet_icon_item {
      border-radius: 20px;
      border: 1px solid #cdcdcd;
      text-align: center;
      padding: 30px;
      box-sizing: border-box;
      h2 {
        font-size: 30px;
        font-weight: 300;
        color: #333333;
        line-height: 1.5;
        img {
          width: 40px;
          display: inline-block;
          vertical-align: text-bottom;
        }
      }
    }
  }
  .MyWallet_title {
    font-size: 35px;
    line-height: 1.5;
    padding-left: 10px;
    border-left: 5px solid #b99267;
    box-sizing: border-box;
    font-weight: normal;
    margin: 20px 15px;
  }
  ul {
    list-style: none;
    width: 100%;
    .MyWallet_item {
      width: 100%;
      padding: 20px;
      box-sizing: border-box;
      background-color: #fff;
      margin-bottom: 20px;
      img {
        width: 100%;
        height: 110px;
        display: block;
        border-radius: 10px;
      }
      .MyWallet_item_name {
        width: 100%;
        padding-left: 20px;
        box-sizing: border-box;
        & > h3 {
          font-size: 30px;
          font-weight: 400;
          color: #000000;
          line-height: 2;
        }
        & > p {
          font-size: 24px;
          font-weight: 300;
          color: #343434;
          line-height: 2;
        }
      }
    }
  }
  .Withdrawal_button {
    position: fixed;
    width: 100%;
    left: 0;
    bottom: 0;
  }
}
</style>
